package service

import (
	"zimuzu_cvn_web_api/model"
	"zimuzu_cvn_web_api/pkg/e"
)

// 商品评论相关代码
type GoodsCommentResponse struct {
	ID         int64
	UID        int64
	GId        int64
	Phone      string
	Content    string
	CreateTime string
}

// 获取商品评论信息接口
// Auth: hzp
func (goods *ShopGoodsService) Comments() (res []GoodsCommentResponse, err error) {

	comments, err := model.ListShopGoodsComment(goods.GId, goods.Page, goods.PageSize)
	if err != nil {
		return res, err
	}
	for _, k := range comments {
		var temp GoodsCommentResponse
		temp.GId = k.GId
		temp.ID = k.ID
		temp.UID = k.UID
		temp.Phone = k.Phone
		temp.Content = k.Content
		temp.CreateTime = e.TimeToStr(k.CreateTime)
		res = append(res, temp)
	}
	return res, nil
}

// 发布评论
// Auth: hzp
func (comment *GoodsCommentResponse) Publish() (err error) {

	var AddComment model.ShopGoodsCommentModel
	AddComment.UID = comment.UID
	AddComment.Phone = comment.Phone
	AddComment.Content = comment.Content
	AddComment.CreateTime = e.StrToTime(comment.CreateTime)
	err = model.CreateShopGoodsComment(AddComment)
	if err != nil {
		return err
	}
	return nil
}

// 删除评论
// Auth: hzp
func (comment *GoodsCommentResponse) Del() (err error) {

	err = model.DelShopGoodsComment(comment.ID)
	if err != nil {
		return err
	}
	return nil
}
